<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>正则</title>
</head>
<body>
  
  <script>
    // 例子1:下划线转驼峰
    var s1 = "get-element-by-id" // 转化为 getElementById
    console.log(s1.match(/\-\w/g));
    var s2 = s1.replace(/\-\w/g,function (item) {
      console.log(item);
      return item.slice(1).toLocaleUpperCase()
    })
    console.log(s2);

    // 例子2:查找字符串中出现最多的字符和个数
    let str = 'abcabcabcbbccicccfsgkll'

    let str2 = str.split('').sort().join('')
    let num = 0
    let char = ''
    // 正则表达式中的\1代表与前面小括号匹配
    str2.replace(/(\w)\1*/g,function ($0,$1) {
      if($0.length>num){
        num = $0.length
        char = $1
      }
    })
    console.log(char,num);
  </script>
</body>
</html>